package org.base.common.listener;

import org.base.common.util.AsyncUtils;
import org.base.common.util.RequestUtils;
import org.base.common.util.SpringContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author He mingliang
 */
@Component
public class ApplicationContextListener implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        SpringContextUtils.setApplicationContext(event.getApplicationContext());
        AsyncUtils.setExecutor(event.getApplicationContext().getBean(ThreadPoolTaskExecutor.class));
    }
}
